<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css"  media="all">
    <script src="/layui/jquery-3.5.1.min.js"></script>
    <script src="/layui/layui.js" charset="utf-8"></script>
    <link rel="shortcut icon"  th:href="@{/static/favicon.ico}"/>
</head>

<body>
<form class="layui-form layui-form-pane" action="/management/getCar" method="post">
<!--    <input type="hidden" th:value="${id}" id="o">-->
    <div class="layui-form-item">

    <div class="layui-inline">
        <label class="layui-form-label">用车时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="timefind" placeholder="yyyy-MM-dd HH:mm:ss" name="startTime" th:value="${startTime}">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="timefind2" placeholder="yyyy-MM-dd HH:mm:ss" name="endTime" th:value="${endTime}">
        </div>
    </div>
        <button class="layui-btn" id="searchBtn">获取可用车辆</button>
    </div>

</form>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">点击派出所选车辆</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,url:'/management/getCar'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,where : {
                startTime :'',endTime:''
            }
            ,title: '派车申请表'
            ,cols: [
                [
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                ,{field:'model', title:'车辆型号', width:120, edit: 'text'}
                ,{field:'licensePlateNumber', title:'车牌号', width:120, edit: 'text', sort: true}
                ,{field:'mileage', title:'里程', width:100}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]
            ]
            ,page: true
        });
        //条件查询
        $('#searchBtn').on('click', function() {
            table.reload('test', {
                where : {
                    startTime : $('#timefind').val(),endTime:$('#timefind2').val()
                },
                page : {
                    curr : 1
                }
            });
            return false;
        });
        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    //var ID = $('#o').val();
                    $.ajax({
                        url:"/management/setCar",
                        data:{"carData":JSON.stringify(data),"bookingCarApplicationId":[[${bookingCarApplicationId}]],"startLocation":"[[${startLocation}]]","endLocation":"[[${endLocation}]]","startTime":"[[${startTime}]]","endTime":"[[${endTime}]]"},
                    })
                    layer.alert("派车成功！");
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('选择你想派的车点派出即可');
                    break;
            };
        });
        table.render({ //其它参数在此省略
            text: {
                none: '输入派车时间获取数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
        });
        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.prompt({
                    formType: 2
                    ,value: data.email
                }, function(value, index){
                    obj.update({
                        email: value
                    });
                    layer.close(index);
                });
            }
        });
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
    //日期时间选择器
    laydate.render({
            elem: '#timefind2'
            ,type: 'datetime'
        });
        //日期时间选择器
        laydate.render({
            elem: '#timefind'
            ,type: 'datetime'
        });
    });
</script>
</body>

</html>